package com.bringway.p2p.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.bringway.framework.dao.BaseJdbcDao;
import com.bringway.p2p.dao.NewsDao;
import com.bringway.p2p.domain.News;
@Repository
public class NewsDaoImpl extends BaseJdbcDao implements NewsDao{
	private class NewsMapper implements RowMapper{
		@Override
		public News mapRow(ResultSet rs, int rowNum) throws SQLException {
			News n = new News();
			n.setTitle(rs.getString("TITLE"));
			n.setContent(rs.getString("CONTENT"));
			n.setFbDate(rs.getString("FB_DATE"));
			n.setFbName(rs.getString("FB_NAME"));
			n.setId(rs.getString("ID"));
			n.setOperDate(rs.getString("OPER_DATE"));
			n.setOperUserId(rs.getString("OPER_USER_ID"));
			return n;
		}
	}
	
	@Override
	public List<News> queryNews() {
		StringBuffer sql = new StringBuffer();
		sql.append("select TITLE,CONTENT,FB_NAME,(DATE_FORMAT(FB_DATE,'%Y-%m-%d  %H:%i:%s')) FB_DATE,ID,OPER_DATE,OPER_USER_ID ");
		sql.append(" from D_CCB_FM.T_FM_SYS_NEWS order by FB_DATE desc");
		List<News> list = this.getNamedParameterJdbcTemplate().query(sql.toString(), new NewsMapper());
		return list;
	}
}
